﻿using System;
using System.Net;
using Lottery.Client.Services.Remote;

namespace Lottery.Client.Services
{
    public class UserService
    {
        private UserServiceClient _userServiceClient;

        public UserServiceClient UserServiceClient
        {
            get { return _userServiceClient ?? (_userServiceClient = new UserServiceClient()); }
        }

        public event EventHandler Loaded;

        public UserInfoResult UserInfoResult { get; private set; }
        public string LoginIp { get; private set; }

        #region Operations

        public void Login(string userName, string passwd)
        {
            UserServiceClient.LoginCompleted += (o, e) =>
            {
                UserInfoResult = e.Result; if (Loaded != null)
            {
                Loaded(this, EventArgs.Empty);
            } };
            UserServiceClient.LoginAsync(userName,passwd);
        }

        #endregion Operations
    }
}